<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- card部分 -->
    <el-card>
        <el-col :span="8">
            <el-input placeholder="请输入内容" v-model="inputvalue" class="input-with-select">
                <el-button slot="append" icon="el-icon-search"></el-button>
            </el-input>
        </el-col>
        <!-- table部分 -->
        <el-table :data="orderData"  border stripe>
            <el-table-column type="index" label="#"></el-table-column>
            <el-table-column prop="order_number" label="订单编号" width="590"></el-table-column>
            <el-table-column prop="order_price" label="订单价格"width="80"></el-table-column>
            <el-table-column prop="order_pay" label="是否付款"width="80"></el-table-column>
            <el-table-column prop="is_send" label="是否发货"width="80"></el-table-column>
            <el-table-column prop="update_time" label="下单时间" width="180">
                <template slot-scope="scope">
                    {{scope.row.update_time|getdate}}
                </template>
            </el-table-column>
            <el-table-column label="操作" >
                <template slot-scope="scope">
                    <el-button size="mini" type="primary" icon="el-icon-edit" @click="editaddress"></el-button>
                     <el-button size="mini" type="success" icon="el-icon-location" @click="editprogress(scope.row)"></el-button>
                </template>
            </el-table-column>
        </el-table>
        <!-- 分页器 -->
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryobj.pagenum"
            :page-sizes="[5, 10, 15, 30]"
            :page-size="queryobj.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalNumber">
        </el-pagination>
    </el-card>

    <!-- 修改地址dialog -->
    <el-dialog
        title="修改地址"
        :visible.sync="editAddressDialogVisible"
        width="50%"
        >
        <!-- form表单 -->
        <el-form :model="orderRuleForm" :rules="orderRuleFormRules" ref="orderRuleFormRef"  label-width="100px">
            <el-form-item label="省市区/县" prop="province">
                <el-cascader
                    :options="cityOptions"
                    @change="changeProvince"
                    v-model="listvalue"
                >
                </el-cascader>
            </el-form-item>
            <el-form-item label="详细地址" prop="detail">
                <el-input v-model="orderRuleForm.detail"></el-input>
            </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="editAddressDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="editAddressDialogVisible = false">确 定</el-button>
        </span>
    </el-dialog>
    
    <!-- 物流进度dialog -->
    <el-dialog
        title="物流进度"
        :visible.sync="progressDialogVisible"
        width="50%"
        > 
        <!-- 倒序排列 -->
        <el-timeline :reverse="true">
            <el-timeline-item
                v-for="(activity, index) in activities"
                :key="index"
                :timestamp="activity.timestamp">
                {{activity.content}}
            </el-timeline-item>
        </el-timeline>
        
        <span slot="footer" class="dialog-footer">
            <el-button @click="progressDialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="progressDialogVisible = false">确 定</el-button>
        </span>
    </el-dialog>
    
  </div>
</template>

<script>
import cityOptions from '@/assets/js/provinces-china-master/city_data2017_element.js'
export default {
    data(){
        return{
            inputvalue:"",
            orderData:[],
            queryobj:{
                query:"",
                pagenum:1,
                pagesize:5
            },
            totalNumber:0,
            editAddressDialogVisible:false,
            orderRuleForm:{
                province:"",
                detail:""
            },
            orderRuleFormRules:{
                province:[
                    { required: true,trigger: 'blur' },
                ],
                detail:[
                    { required: true, message: '请输入详细地址', trigger: 'blur' },
                ]
            },
            cityOptions:cityOptions,
            listvalue:[],
            progressDialogVisible:false,
            activities: [{
            content: '活动按期开始',
            timestamp: '2018-04-15'
            }, {
            content: '通过审核',
            timestamp: '2018-04-13'
            }, {
            content: '创建成功',
            timestamp: '2018-04-11'
            }]
            }
    },
    created(){
        this.getordersdata();
    },
    methods:{
        async getordersdata(){
            let {data:res} = await this.$axios.get("http://timemeetyou.com:8889/api/private/v1/orders",{
                params:this.queryobj
            })
            if(res.meta.status===200){
                this.$message.success("获取订单数据成功!")
            }
            this.orderData = res.data.goods;
            this.totalNumber = res.data.total;
            console.log(res)
        },
        handleSizeChange(value){
            this.queryobj.pagesize = value;
            this.getordersdata();
        },
        handleCurrentChange(value){
            this.queryobj.pagenum = value;
            this.getordersdata();
        },
        editaddress(){
            this.editAddressDialogVisible=true
        },
        changeProvince(value){
            console.log(this.listvalue)
        },
        async editprogress(){
            this.progressDialogVisible = true
            //查看物流信息


        }
    }
};
</script>

<style lang="less" scoped>
.el-breadcrumb,.el-input,.el-table{
  margin-bottom: 15px;
}
.el-cascader{
    width: 100%;
}

</style>